package common

import (
	"math"
	"public/tools"
	"time"
)

func CreateUnique(channal string) string {
	tmp := time.Now().Format("20060102150405") + channal
	tmp = tmp + tools.GetRandomString(32-len(tmp))
	return tmp
}

//计算两个位置之间距离 单位：m
func EarthDistance(lat1, lon1, lat2, lon2 float64) float64 {
	radius := 6371000 // 6378137
	rad := math.Pi / 180.0

	lat1 = lat1 * rad
	lon1 = lon1 * rad
	lat2 = lat2 * rad
	lon2 = lon2 * rad

	theta := lon2 - lon1
	dist := math.Acos(math.Sin(lat1)*math.Sin(lat2) + math.Cos(lat1)*math.Cos(lat2)*math.Cos(theta))

	return dist * float64(radius)
}
